<template>
  <div class="app-container">
    <div class="app-title">
      <span>十三月工资年结 </span>
    </div>
    <el-row :gutter="20">
      <el-col :span="8">
        <el-col :span="1">
          <i
            :class="[treeShow ? 'el-icon-s-fold treeI': 'el-icon-s-unfold treeI']"
            @click="toggerTree"
          />
        </el-col>
        <div class="tap-fillet">
          <el-radio-group
            v-model="activeName"
            style="margin-left:4rem; width:700px; height:15px; margin-top:-57px "
          >
            <el-radio-button
              label="0"
              name="notEnd"
            ><img
          style="height:12px;"
          :src="Untreatedimg"
        >未结</el-radio-button>
            <el-radio-button
              label="1"
              name="isEnd"
            ><img
          style=" height:12px;"
          :src="Processedimg"
        >已结</el-radio-button>
          </el-radio-group>
        </div>
      </el-col>
      <div class="filter-container">
        <el-col
          style="text-align:right;margin-top: -3px;"
          :span="16"
        >
          <div v-if="activeName === '1'" class="salary-month">
            <span>年份</span>
            <el-date-picker
              v-model="salaryYear"
              type="year"
              placeholder="请选择年份"
              :clearable="false"
              format="yyyy"
              value-format="yyyy"
              :editable="false"
            />
          </div>
          <el-button
            v-if="activeName === '0'"
            size="small"
            class="filter-item"
            style="margin-left: 10px;"
            type="primary"
            :loading="monthLoading"
            @click="MonthEnd"
          >
            年结
          </el-button>
          <el-button
            v-if="activeName === '1'"
            size="small"
            class="filter-item"
            style="margin-left: 10px;"
            type="primary"
            :loading="revokeMonthLoading"
            @click="revokeMonthEnd"
          >
            撤销年结
          </el-button>
       
        </el-col>

      </div>
    </el-row>
    <div
      ref="box"
      class="box"
    >
      <div
        class="left"
        :class="[isActive ? 'wid':'wids']"
      >
        <div
          :class="[treeShow ? 'treeShow' : 'treeNotShow']"
          :style="{'height' : treeHeight + 'px'}"
        >
          <AgencyTree
            class="agencyTree"
            @handleTreeQuery="handleTreeQuery"
          />
        </div>
      </div>
      <div
        v-show="Show"
        class="resize"
        title="收缩侧边栏"
      />
      <div
        class="mid"
        :class="[isActive ? 'mids': 'min']"
      >
        <salaryMonthEndChildren
          :key="timer"
          ref="chil"
          :year="salaryYear"
          :tab-pane="activeName"
          :tree-data="treeData"
          @monthEndCallback="monthEndCallback()"
          @revokeMonthEndCallback="revokeMonthEndCallback()"
          @makeSalaryDataCallback="makeSalaryDataCallback"
        />
      </div>
      <Drag ref="icon" />

    </div>
  </div>
</template>

<script>
import salaryMonthEndChildren from '@/views/thirteen/children/salaryMonthEndChildren'
import AgencyTree from '@/components/tree/agencyTree'
import Drag from '@/components/Drag'
export default {
  name: 'ComplexTable',
  components: { salaryMonthEndChildren, AgencyTree, Drag },
  data() {
    return {
      salaryYear: '',
      treeHeight: null,
      Show: false,
      isActive: true,
      treeShow: false,
      treeData: '',
      timer: '',
      monthLoading: false,
      revokeMonthLoading: false,
      activeName: '0',
      Untreatedimg: require('@/assets/images/select.png'),
      Processedimg: require('@/assets/images/processed.png')
    }
  },
  watch: {
    activeName(val) {
      this.timer = new Date().getTime()
      if (val === '0') {
        this.Processedimg = require('@/assets/images/processed.png')
        this.Untreatedimg = require('@/assets/images/select.png')
      } else {
        this.Processedimg = require('@/assets/images/blue.png')
        this.Untreatedimg = require('@/assets/images/blueselect.png')
      }
    }
  },
    beforeDestroy() {
    clearInterval(this.timer)
  },
  created() {
    this.salaryYear =  new Date().getFullYear()+''
  },
  mounted() {
    this.dragController()
    this.getTeHeight()
  },
  beforeMount() {
    window.addEventListener('resize', this.getTeHeight)
  },
  methods: {
    processnode() {
      this.$refs.chil.processnode()
    },
    getTeHeight() {
      this.treeHeight = window.innerHeight - 270
    },
    // 拖拽
    dragController() {
      this.$refs.icon.dragControllerDiv()
    },
    // 树显隐方法
    toggerTree() {
      this.treeShow = !this.treeShow
      this.isActive = !this.isActive
      this.Show = !this.Show
    },
    // 树方法
    handleTreeQuery(data) {
      this.treeData = data
      this.$refs.chil.handleTree(data)
    },
  //  showProgress() {
  //     this.makeLoading = true
  //     this.$refs.chil.show()
  //   },
    // 月结
    MonthEnd() {
      this.monthLoading = true
      this.$refs.chil.saveMonthEnd()
    },
    makeSalaryDataCallback() {
      this.makeLoading = !this.makeLoading
      this.salaCardBank = ''
    },
    monthEndCallback() {
      this.monthLoading = !this.monthLoading
    },
    revokeMonthEnd() {
      this.revokeMonthLoading = true
      this.$refs.chil.revokeMonthEnd()
    },
    revokeMonthEndCallback() {
      this.revokeMonthLoading = false
    },
    // 导出
    outPutFile() {
      this.$refs.chil.outPutFile()
    }
  }
}
</script>
<style lang="scss" scoped>
@import "~@/styles/border.scss"; /*引入公共样式*/

.app-title {
  margin-bottom: 15px;
  height: 20px;
  border-bottom: 1px solid #DCDFE6;
}
  .salary-month {
    display: inline-block;
    vertical-align: top;
  }

</style>
